import { orderDispatchNetwork } from '@/api/order'
import { ref } from 'vue'

const useAssignNetworkForm = () => {
  const formData = ref<{ networkId: string | null; remark: string; networkEmpId: string | null }>({
    networkId: null,
    remark: '',
    networkEmpId: null,
  })

  const submitLoading = ref(false)

  const submit = async (workIds: Array<string>) => {
    submitLoading.value = true
    const res = await orderDispatchNetwork({
      networkEmpId: formData.value.networkEmpId,
      networkId: formData.value.networkId,
      workIds,
      remark: formData.value.remark,
    })
    submitLoading.value = false
    return res.data as {
      message: string
      success: boolean
      data: object
      code: number
    }
  }

  const reset = () => {
    formData.value.networkEmpId = null
    formData.value.remark = ''
    formData.value.networkId = null
  }

  return {
    formData,
    submitLoading,
    reset,
    submit,
  }
}

export default useAssignNetworkForm
